package com.example.sailongai.util;

import org.springframework.web.multipart.MultipartFile;
import java.util.Base64;
import java.io.IOException;

public class ImageUtils {

    // 方法1：转换为Base64（适合小文件）
    public static String toBase64(MultipartFile file) throws IOException {
        byte[] bytes = file.getBytes();
        return "data:image/png;base64," + Base64.getEncoder().encodeToString(bytes);
    }

    // 方法2：上传到阿里云OSS并返回URL（需配置OSS）
    /*
    public static String uploadToOSS(MultipartFile file, OSS ossClient, String bucketName) throws IOException {
        String fileName = "flowchart_" + System.currentTimeMillis() + ".png";
        ossClient.putObject(bucketName, fileName, new ByteArrayInputStream(file.getBytes()));
        return "https://" + bucketName + ".oss-cn-hangzhou.aliyuncs.com/" + fileName;
    }
    */
}